
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/29/2011 00:53:21
-- Generated from EDMX file: C:\Users\Henrique Graça\Documents\Visual Studio 2010\Projects\cantinho\Domain\ModeloCantinho.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Cantinho];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AnswerComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comment] DROP CONSTRAINT [FK_AnswerComment];
GO
IF OBJECT_ID(N'[dbo].[FK_CoresSigno_Cores]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CoresSigno] DROP CONSTRAINT [FK_CoresSigno_Cores];
GO
IF OBJECT_ID(N'[dbo].[FK_CoresSigno_Signo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CoresSigno] DROP CONSTRAINT [FK_CoresSigno_Signo];
GO
IF OBJECT_ID(N'[dbo].[FK_NewsletterMailingList_MailingList]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NewsletterMailingList] DROP CONSTRAINT [FK_NewsletterMailingList_MailingList];
GO
IF OBJECT_ID(N'[dbo].[FK_NewsletterMailingList_Newsletter]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[NewsletterMailingList] DROP CONSTRAINT [FK_NewsletterMailingList_Newsletter];
GO
IF OBJECT_ID(N'[dbo].[FK_QuestionAnswer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Answer] DROP CONSTRAINT [FK_QuestionAnswer];
GO
IF OBJECT_ID(N'[dbo].[FK_QuestionTag_Question]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[QuestionTag] DROP CONSTRAINT [FK_QuestionTag_Question];
GO
IF OBJECT_ID(N'[dbo].[FK_QuestionTag_Tag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[QuestionTag] DROP CONSTRAINT [FK_QuestionTag_Tag];
GO
IF OBJECT_ID(N'[dbo].[FK_RelacaoSignoSigno]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RelacaoSigno] DROP CONSTRAINT [FK_RelacaoSignoSigno];
GO
IF OBJECT_ID(N'[dbo].[FK_RelacaoSignoSigno1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RelacaoSigno] DROP CONSTRAINT [FK_RelacaoSignoSigno1];
GO
IF OBJECT_ID(N'[dbo].[FK_SignoChinesDatasSignoChines]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DatasSignoChines] DROP CONSTRAINT [FK_SignoChinesDatasSignoChines];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAnswer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Answer] DROP CONSTRAINT [FK_UserAnswer];
GO
IF OBJECT_ID(N'[dbo].[FK_UserComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comment] DROP CONSTRAINT [FK_UserComment];
GO
IF OBJECT_ID(N'[dbo].[FK_UserFilho_Filho]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserFilho] DROP CONSTRAINT [FK_UserFilho_Filho];
GO
IF OBJECT_ID(N'[dbo].[FK_UserFilho_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserFilho] DROP CONSTRAINT [FK_UserFilho_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserGrupo_Grupo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserGrupo] DROP CONSTRAINT [FK_UserGrupo_Grupo];
GO
IF OBJECT_ID(N'[dbo].[FK_UserGrupo_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserGrupo] DROP CONSTRAINT [FK_UserGrupo_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserNewsletter_Newsletter]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserNewsletter] DROP CONSTRAINT [FK_UserNewsletter_Newsletter];
GO
IF OBJECT_ID(N'[dbo].[FK_UserNewsletter_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserNewsletter] DROP CONSTRAINT [FK_UserNewsletter_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPonto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ponto] DROP CONSTRAINT [FK_UserPonto];
GO
IF OBJECT_ID(N'[dbo].[FK_UserQuestion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Question] DROP CONSTRAINT [FK_UserQuestion];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRole] DROP CONSTRAINT [FK_UserRole_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserRole] DROP CONSTRAINT [FK_UserRole_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Answer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Answer];
GO
IF OBJECT_ID(N'[dbo].[Artigo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Artigo];
GO
IF OBJECT_ID(N'[dbo].[Comment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Comment];
GO
IF OBJECT_ID(N'[dbo].[Cores]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cores];
GO
IF OBJECT_ID(N'[dbo].[CoresSigno]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CoresSigno];
GO
IF OBJECT_ID(N'[dbo].[DatasFamosas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DatasFamosas];
GO
IF OBJECT_ID(N'[dbo].[DatasSignoChines]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DatasSignoChines];
GO
IF OBJECT_ID(N'[dbo].[Filho]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Filho];
GO
IF OBJECT_ID(N'[dbo].[Grupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Grupo];
GO
IF OBJECT_ID(N'[dbo].[MailingList]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MailingList];
GO
IF OBJECT_ID(N'[dbo].[Newsletter]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Newsletter];
GO
IF OBJECT_ID(N'[dbo].[NewsletterMailingList]', 'U') IS NOT NULL
    DROP TABLE [dbo].[NewsletterMailingList];
GO
IF OBJECT_ID(N'[dbo].[Nome]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Nome];
GO
IF OBJECT_ID(N'[dbo].[Ponto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ponto];
GO
IF OBJECT_ID(N'[dbo].[Question]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Question];
GO
IF OBJECT_ID(N'[dbo].[QuestionTag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[QuestionTag];
GO
IF OBJECT_ID(N'[dbo].[RelacaoSigno]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RelacaoSigno];
GO
IF OBJECT_ID(N'[dbo].[Role]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Role];
GO
IF OBJECT_ID(N'[dbo].[Signo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Signo];
GO
IF OBJECT_ID(N'[dbo].[SignoChines]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SignoChines];
GO
IF OBJECT_ID(N'[dbo].[Tag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tag];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[UserFilho]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserFilho];
GO
IF OBJECT_ID(N'[dbo].[UserGrupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserGrupo];
GO
IF OBJECT_ID(N'[dbo].[UserNewsletter]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserNewsletter];
GO
IF OBJECT_ID(N'[dbo].[UserRole]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRole];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Nome'
CREATE TABLE [dbo].[Nome] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NomeProprio] nvarchar(40)  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [Votos] int  NULL,
    [Genero] nvarchar(1)  NOT NULL
);
GO

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Comment] nvarchar(max)  NULL,
    [Password] nvarchar(max)  NOT NULL,
    [PasswordQuestion] nvarchar(max)  NULL,
    [PasswordAnswer] nvarchar(max)  NULL,
    [IsAnonymous] bit  NULL,
    [IsApproved] bit  NOT NULL,
    [LastActivityDate] datetime  NOT NULL,
    [LastLoginDate] datetime  NOT NULL,
    [LastPasswordChangedDate] datetime  NULL,
    [CreationDate] datetime  NOT NULL,
    [IsOnLine] bit  NULL,
    [IsLockedOut] bit  NOT NULL,
    [LastLockedOutDate] datetime  NULL,
    [FailedPasswordAttemptCount] int  NOT NULL,
    [FailedPasswordAttemptWindowStart] datetime  NULL,
    [FailedPasswordAnswerAttemptCount] int  NOT NULL,
    [FailedPasswordAnswerAttemptWindowStart] datetime  NULL,
    [LastLoginIP] nvarchar(40)  NULL,
    [NewPasswordRequestDate] datetime  NULL,
    [EmailParceiro] nvarchar(max)  NULL,
    [Genero] nvarchar(1)  NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [EmailKey] nvarchar(max)  NULL,
    [Foto] nvarchar(max)  NULL
);
GO

-- Creating table 'Role'
CREATE TABLE [dbo].[Role] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RoleName] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Artigo'
CREATE TABLE [dbo].[Artigo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(350)  NOT NULL,
    [Activo] bit  NOT NULL,
    [Data] datetime  NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Imagem] nvarchar(max)  NOT NULL,
    [Texto] nvarchar(max)  NULL,
    [Link1] nvarchar(max)  NULL,
    [Link2] nvarchar(max)  NULL,
    [TextoLink1] nvarchar(max)  NULL,
    [TextoLink2] nvarchar(max)  NULL,
    [IsNovidade] bit  NOT NULL
);
GO

-- Creating table 'Newsletter'
CREATE TABLE [dbo].[Newsletter] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [Activo] bit  NOT NULL,
    [HTML] nvarchar(max)  NOT NULL,
    [Registo] bit  NOT NULL
);
GO

-- Creating table 'MailingList'
CREATE TABLE [dbo].[MailingList] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Activo] bit  NOT NULL,
    [DataNascimento] datetime  NOT NULL,
    [DataFormatada] nvarchar(max)  NOT NULL,
    [TentarEngravidar] bit  NOT NULL
);
GO

-- Creating table 'Filho'
CREATE TABLE [dbo].[Filho] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [DataNascimento] datetime  NOT NULL,
    [DataFormatada] nvarchar(max)  NOT NULL,
    [Genero] nvarchar(1)  NOT NULL,
    [Foto] nvarchar(max)  NULL,
    [Activo] bit  NOT NULL,
    [DataInserido] datetime  NOT NULL
);
GO

-- Creating table 'Grupo'
CREATE TABLE [dbo].[Grupo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [DataCricacao] datetime  NOT NULL,
    [Activo] bit  NOT NULL
);
GO

-- Creating table 'SignoChines'
CREATE TABLE [dbo].[SignoChines] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Animal] nvarchar(max)  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [DescrCrianca] nvarchar(max)  NOT NULL,
    [Personalidades] nvarchar(max)  NOT NULL,
    [Profissao] nvarchar(max)  NOT NULL,
    [Financas] nvarchar(max)  NOT NULL,
    [Imagem] nvarchar(max)  NOT NULL,
    [Cor] nvarchar(max)  NOT NULL,
    [Numeros] nvarchar(max)  NOT NULL,
    [Compatibilidades] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Signo'
CREATE TABLE [dbo].[Signo] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DiaInicial] datetime  NOT NULL,
    [DiaFinal] datetime  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [Imagem] nvarchar(max)  NOT NULL,
    [Elemento] nvarchar(max)  NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [IsPai] bit  NOT NULL
);
GO

-- Creating table 'RelacaoSigno'
CREATE TABLE [dbo].[RelacaoSigno] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [SignoId1] int  NOT NULL,
    [SignoId2] int  NOT NULL
);
GO

-- Creating table 'DatasFamosas'
CREATE TABLE [dbo].[DatasFamosas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Data] nvarchar(max)  NOT NULL,
    [Nome] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Cores'
CREATE TABLE [dbo].[Cores] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Cor] nvarchar(max)  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DatasSignoChines'
CREATE TABLE [dbo].[DatasSignoChines] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DataInicial] datetime  NOT NULL,
    [DataFinal] datetime  NOT NULL,
    [SignoChinesId] int  NOT NULL
);
GO

-- Creating table 'Tag'
CREATE TABLE [dbo].[Tag] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TagName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Question'
CREATE TABLE [dbo].[Question] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Body] nvarchar(max)  NOT NULL,
    [Votes] int  NOT NULL,
    [Views] int  NOT NULL,
    [DateCreated] datetime  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'Answer'
CREATE TABLE [dbo].[Answer] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Text] nvarchar(max)  NOT NULL,
    [Votes] int  NOT NULL,
    [DateCreated] datetime  NOT NULL,
    [QuestionId] int  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'Comment'
CREATE TABLE [dbo].[Comment] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [AnswerId] int  NOT NULL,
    [Body] nvarchar(max)  NOT NULL,
    [UserId] int  NOT NULL,
    [Data] datetime  NOT NULL
);
GO

-- Creating table 'Ponto'
CREATE TABLE [dbo].[Ponto] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Perguntas] int  NOT NULL,
    [Respostas] int  NOT NULL,
    [Comentarios] int  NOT NULL,
    [DataAct] datetime  NOT NULL,
    [PerguntaVotopositivo] int  NOT NULL,
    [RespostaVotoPositivo] int  NOT NULL,
    [Total] int  NULL,
    [RespostaCorrecta] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'UserRole'
CREATE TABLE [dbo].[UserRole] (
    [User_Id] int  NOT NULL,
    [Role_Id] int  NOT NULL
);
GO

-- Creating table 'NewsletterMailingList'
CREATE TABLE [dbo].[NewsletterMailingList] (
    [Newsletter_Id] int  NOT NULL,
    [MailingList_Id] int  NOT NULL
);
GO

-- Creating table 'UserFilho'
CREATE TABLE [dbo].[UserFilho] (
    [User_Id] int  NOT NULL,
    [Filho_Id] int  NOT NULL
);
GO

-- Creating table 'UserNewsletter'
CREATE TABLE [dbo].[UserNewsletter] (
    [User_Id] int  NOT NULL,
    [Newsletter_Id] int  NOT NULL
);
GO

-- Creating table 'UserGrupo'
CREATE TABLE [dbo].[UserGrupo] (
    [User_Id] int  NOT NULL,
    [Grupo_Id] int  NOT NULL
);
GO

-- Creating table 'CoresSigno'
CREATE TABLE [dbo].[CoresSigno] (
    [Cores_Id] int  NOT NULL,
    [Signo_Id] int  NOT NULL
);
GO

-- Creating table 'QuestionTag'
CREATE TABLE [dbo].[QuestionTag] (
    [Question_Id] int  NOT NULL,
    [Tag_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Nome'
ALTER TABLE [dbo].[Nome]
ADD CONSTRAINT [PK_Nome]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Role'
ALTER TABLE [dbo].[Role]
ADD CONSTRAINT [PK_Role]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Artigo'
ALTER TABLE [dbo].[Artigo]
ADD CONSTRAINT [PK_Artigo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Newsletter'
ALTER TABLE [dbo].[Newsletter]
ADD CONSTRAINT [PK_Newsletter]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MailingList'
ALTER TABLE [dbo].[MailingList]
ADD CONSTRAINT [PK_MailingList]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Filho'
ALTER TABLE [dbo].[Filho]
ADD CONSTRAINT [PK_Filho]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Grupo'
ALTER TABLE [dbo].[Grupo]
ADD CONSTRAINT [PK_Grupo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SignoChines'
ALTER TABLE [dbo].[SignoChines]
ADD CONSTRAINT [PK_SignoChines]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Signo'
ALTER TABLE [dbo].[Signo]
ADD CONSTRAINT [PK_Signo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RelacaoSigno'
ALTER TABLE [dbo].[RelacaoSigno]
ADD CONSTRAINT [PK_RelacaoSigno]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DatasFamosas'
ALTER TABLE [dbo].[DatasFamosas]
ADD CONSTRAINT [PK_DatasFamosas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Cores'
ALTER TABLE [dbo].[Cores]
ADD CONSTRAINT [PK_Cores]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DatasSignoChines'
ALTER TABLE [dbo].[DatasSignoChines]
ADD CONSTRAINT [PK_DatasSignoChines]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tag'
ALTER TABLE [dbo].[Tag]
ADD CONSTRAINT [PK_Tag]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Question'
ALTER TABLE [dbo].[Question]
ADD CONSTRAINT [PK_Question]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Answer'
ALTER TABLE [dbo].[Answer]
ADD CONSTRAINT [PK_Answer]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Comment'
ALTER TABLE [dbo].[Comment]
ADD CONSTRAINT [PK_Comment]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Ponto'
ALTER TABLE [dbo].[Ponto]
ADD CONSTRAINT [PK_Ponto]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [User_Id], [Role_Id] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [PK_UserRole]
    PRIMARY KEY NONCLUSTERED ([User_Id], [Role_Id] ASC);
GO

-- Creating primary key on [Newsletter_Id], [MailingList_Id] in table 'NewsletterMailingList'
ALTER TABLE [dbo].[NewsletterMailingList]
ADD CONSTRAINT [PK_NewsletterMailingList]
    PRIMARY KEY NONCLUSTERED ([Newsletter_Id], [MailingList_Id] ASC);
GO

-- Creating primary key on [User_Id], [Filho_Id] in table 'UserFilho'
ALTER TABLE [dbo].[UserFilho]
ADD CONSTRAINT [PK_UserFilho]
    PRIMARY KEY NONCLUSTERED ([User_Id], [Filho_Id] ASC);
GO

-- Creating primary key on [User_Id], [Newsletter_Id] in table 'UserNewsletter'
ALTER TABLE [dbo].[UserNewsletter]
ADD CONSTRAINT [PK_UserNewsletter]
    PRIMARY KEY NONCLUSTERED ([User_Id], [Newsletter_Id] ASC);
GO

-- Creating primary key on [User_Id], [Grupo_Id] in table 'UserGrupo'
ALTER TABLE [dbo].[UserGrupo]
ADD CONSTRAINT [PK_UserGrupo]
    PRIMARY KEY NONCLUSTERED ([User_Id], [Grupo_Id] ASC);
GO

-- Creating primary key on [Cores_Id], [Signo_Id] in table 'CoresSigno'
ALTER TABLE [dbo].[CoresSigno]
ADD CONSTRAINT [PK_CoresSigno]
    PRIMARY KEY NONCLUSTERED ([Cores_Id], [Signo_Id] ASC);
GO

-- Creating primary key on [Question_Id], [Tag_Id] in table 'QuestionTag'
ALTER TABLE [dbo].[QuestionTag]
ADD CONSTRAINT [PK_QuestionTag]
    PRIMARY KEY NONCLUSTERED ([Question_Id], [Tag_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [User_Id] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [FK_UserRole_User]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Role_Id] in table 'UserRole'
ALTER TABLE [dbo].[UserRole]
ADD CONSTRAINT [FK_UserRole_Role]
    FOREIGN KEY ([Role_Id])
    REFERENCES [dbo].[Role]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserRole_Role'
CREATE INDEX [IX_FK_UserRole_Role]
ON [dbo].[UserRole]
    ([Role_Id]);
GO

-- Creating foreign key on [Newsletter_Id] in table 'NewsletterMailingList'
ALTER TABLE [dbo].[NewsletterMailingList]
ADD CONSTRAINT [FK_NewsletterMailingList_Newsletter]
    FOREIGN KEY ([Newsletter_Id])
    REFERENCES [dbo].[Newsletter]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MailingList_Id] in table 'NewsletterMailingList'
ALTER TABLE [dbo].[NewsletterMailingList]
ADD CONSTRAINT [FK_NewsletterMailingList_MailingList]
    FOREIGN KEY ([MailingList_Id])
    REFERENCES [dbo].[MailingList]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NewsletterMailingList_MailingList'
CREATE INDEX [IX_FK_NewsletterMailingList_MailingList]
ON [dbo].[NewsletterMailingList]
    ([MailingList_Id]);
GO

-- Creating foreign key on [User_Id] in table 'UserFilho'
ALTER TABLE [dbo].[UserFilho]
ADD CONSTRAINT [FK_UserFilho_User]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Filho_Id] in table 'UserFilho'
ALTER TABLE [dbo].[UserFilho]
ADD CONSTRAINT [FK_UserFilho_Filho]
    FOREIGN KEY ([Filho_Id])
    REFERENCES [dbo].[Filho]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserFilho_Filho'
CREATE INDEX [IX_FK_UserFilho_Filho]
ON [dbo].[UserFilho]
    ([Filho_Id]);
GO

-- Creating foreign key on [User_Id] in table 'UserNewsletter'
ALTER TABLE [dbo].[UserNewsletter]
ADD CONSTRAINT [FK_UserNewsletter_User]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Newsletter_Id] in table 'UserNewsletter'
ALTER TABLE [dbo].[UserNewsletter]
ADD CONSTRAINT [FK_UserNewsletter_Newsletter]
    FOREIGN KEY ([Newsletter_Id])
    REFERENCES [dbo].[Newsletter]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserNewsletter_Newsletter'
CREATE INDEX [IX_FK_UserNewsletter_Newsletter]
ON [dbo].[UserNewsletter]
    ([Newsletter_Id]);
GO

-- Creating foreign key on [User_Id] in table 'UserGrupo'
ALTER TABLE [dbo].[UserGrupo]
ADD CONSTRAINT [FK_UserGrupo_User]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Grupo_Id] in table 'UserGrupo'
ALTER TABLE [dbo].[UserGrupo]
ADD CONSTRAINT [FK_UserGrupo_Grupo]
    FOREIGN KEY ([Grupo_Id])
    REFERENCES [dbo].[Grupo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserGrupo_Grupo'
CREATE INDEX [IX_FK_UserGrupo_Grupo]
ON [dbo].[UserGrupo]
    ([Grupo_Id]);
GO

-- Creating foreign key on [Cores_Id] in table 'CoresSigno'
ALTER TABLE [dbo].[CoresSigno]
ADD CONSTRAINT [FK_CoresSigno_Cores]
    FOREIGN KEY ([Cores_Id])
    REFERENCES [dbo].[Cores]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Signo_Id] in table 'CoresSigno'
ALTER TABLE [dbo].[CoresSigno]
ADD CONSTRAINT [FK_CoresSigno_Signo]
    FOREIGN KEY ([Signo_Id])
    REFERENCES [dbo].[Signo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CoresSigno_Signo'
CREATE INDEX [IX_FK_CoresSigno_Signo]
ON [dbo].[CoresSigno]
    ([Signo_Id]);
GO

-- Creating foreign key on [SignoChinesId] in table 'DatasSignoChines'
ALTER TABLE [dbo].[DatasSignoChines]
ADD CONSTRAINT [FK_SignoChinesDatasSignoChines]
    FOREIGN KEY ([SignoChinesId])
    REFERENCES [dbo].[SignoChines]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SignoChinesDatasSignoChines'
CREATE INDEX [IX_FK_SignoChinesDatasSignoChines]
ON [dbo].[DatasSignoChines]
    ([SignoChinesId]);
GO

-- Creating foreign key on [SignoId1] in table 'RelacaoSigno'
ALTER TABLE [dbo].[RelacaoSigno]
ADD CONSTRAINT [FK_RelacaoSignoSigno]
    FOREIGN KEY ([SignoId1])
    REFERENCES [dbo].[Signo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RelacaoSignoSigno'
CREATE INDEX [IX_FK_RelacaoSignoSigno]
ON [dbo].[RelacaoSigno]
    ([SignoId1]);
GO

-- Creating foreign key on [SignoId2] in table 'RelacaoSigno'
ALTER TABLE [dbo].[RelacaoSigno]
ADD CONSTRAINT [FK_RelacaoSignoSigno1]
    FOREIGN KEY ([SignoId2])
    REFERENCES [dbo].[Signo]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RelacaoSignoSigno1'
CREATE INDEX [IX_FK_RelacaoSignoSigno1]
ON [dbo].[RelacaoSigno]
    ([SignoId2]);
GO

-- Creating foreign key on [Question_Id] in table 'QuestionTag'
ALTER TABLE [dbo].[QuestionTag]
ADD CONSTRAINT [FK_QuestionTag_Question]
    FOREIGN KEY ([Question_Id])
    REFERENCES [dbo].[Question]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Tag_Id] in table 'QuestionTag'
ALTER TABLE [dbo].[QuestionTag]
ADD CONSTRAINT [FK_QuestionTag_Tag]
    FOREIGN KEY ([Tag_Id])
    REFERENCES [dbo].[Tag]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_QuestionTag_Tag'
CREATE INDEX [IX_FK_QuestionTag_Tag]
ON [dbo].[QuestionTag]
    ([Tag_Id]);
GO

-- Creating foreign key on [QuestionId] in table 'Answer'
ALTER TABLE [dbo].[Answer]
ADD CONSTRAINT [FK_QuestionAnswer]
    FOREIGN KEY ([QuestionId])
    REFERENCES [dbo].[Question]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_QuestionAnswer'
CREATE INDEX [IX_FK_QuestionAnswer]
ON [dbo].[Answer]
    ([QuestionId]);
GO

-- Creating foreign key on [AnswerId] in table 'Comment'
ALTER TABLE [dbo].[Comment]
ADD CONSTRAINT [FK_AnswerComment]
    FOREIGN KEY ([AnswerId])
    REFERENCES [dbo].[Answer]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnswerComment'
CREATE INDEX [IX_FK_AnswerComment]
ON [dbo].[Comment]
    ([AnswerId]);
GO

-- Creating foreign key on [UserId] in table 'Comment'
ALTER TABLE [dbo].[Comment]
ADD CONSTRAINT [FK_UserComment]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserComment'
CREATE INDEX [IX_FK_UserComment]
ON [dbo].[Comment]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'Answer'
ALTER TABLE [dbo].[Answer]
ADD CONSTRAINT [FK_UserAnswer]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAnswer'
CREATE INDEX [IX_FK_UserAnswer]
ON [dbo].[Answer]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'Question'
ALTER TABLE [dbo].[Question]
ADD CONSTRAINT [FK_UserQuestion]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserQuestion'
CREATE INDEX [IX_FK_UserQuestion]
ON [dbo].[Question]
    ([UserId]);
GO

-- Creating foreign key on [User_Id] in table 'Ponto'
ALTER TABLE [dbo].[Ponto]
ADD CONSTRAINT [FK_UserPonto]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserPonto'
CREATE INDEX [IX_FK_UserPonto]
ON [dbo].[Ponto]
    ([User_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------